﻿using System;
using System.Collections.Generic;
using System.Windows.Controls;

namespace AgLux
{
    /// <summary>
    /// Represents a canvas that displays a course.
    /// </summary>
    /// 
    public class Course : Canvas
    {
        private string _title, _description;
        private Structure _sections;

        private Navigator _navigator;
        private Introduction _introduction;
        private Summary _summary;

        /// <summary>
        /// Initializes a new instance of the Course class.
        /// </summary>

        /// <param name="title">
        /// The title of the course.
        /// </param>

        /// <param name="description">
        /// The description of the course.
        /// </param>

        /// <param name="sections">
        /// The tree structure of course sections.
        /// </param>

        public Course(string title, string description, Structure sections)
            : base()
        {
            _title = title;
            _description = description;
            _sections = sections;

            _navigator = new Navigator(_sections);
            _introduction = new Introduction(_title, _description);
            _summary = new Summary(_title, _description);

            _introduction.Leave += new EventHandler(ShowNavigator);
            _summary.Leave += new EventHandler(ShowNavigator);

            _navigator.LeaveForIntroduction += new EventHandler(ShowIntroduction);
            _navigator.LeaveForSummary += new EventHandler(ShowSummary);

            Children.Add(_introduction);
        }

        /// <summary>
        /// Occurs when it is time to display the Navigator object.
        /// </summary>

        /// <param name="sender">
        /// The object that raised the event.
        /// </param>

        /// <param name="args">
        /// The EventArgs that contains the event data.
        /// </param>

        private void ShowNavigator(object sender, EventArgs args)
        {
            _navigator.LoadSection(_sections.FirstSection());

            Children.Clear();
            Children.Add(_navigator);
        }

        /// <summary>
        /// Occurs when it is time to display the Introduction object.
        /// </summary>

        /// <param name="sender">
        /// The object that raised the event.
        /// </param>

        /// <param name="args">
        /// The EventArgs that contains the event data.
        /// </param>

        private void ShowIntroduction(object sender, EventArgs args)
        {
            Children.Clear();
            Children.Add(_introduction);
        }

        /// <summary>
        /// Occurs when it is time to display the Summary object.
        /// </summary>

        /// <param name="sender">
        /// The object that raised the event.
        /// </param>

        /// <param name="args">
        /// The EventArgs that contains the event data.
        /// </param>

        private void ShowSummary(object sender, EventArgs args)
        {
            Children.Clear();
            Children.Add(_summary);
        }
    }
}
